package com.atguigu.gulimall.ware.dao;

import com.atguigu.gulimall.ware.entity.WareSkuEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 商品库存
 * 
 * @author dingchunlin
 * @email dingchunlin@gmail.com
 * @date 2023-11-27 13:15:12
 */
@Mapper
public interface WareSkuDao extends BaseMapper<WareSkuEntity> {

    @Select("select count(*) from wms_ware_sku where sku_id = #{skuId} and ware_id = #{wareId}")
    Integer selectCount(@Param("skuId") Long skuId, @Param("wareId") Long wareId);

    @Update("update wms_ware_sku set stock = stock + #{stock} where sku_id = #{skuId} and ware_id = #{wareId}")
    void addStock(@Param("skuId") Long skuId, @Param("wareId") Long wareId, @Param("stock") Integer stock);

    Long getSkuStock(Long skuId);
}
